package com.dgut.dao;

import com.dgut.domain.IRole;
import com.dgut.domain.IUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository("iAuthRepository")
@Mapper
public interface IAuthRepository {
    /**
     * 根据用户名查找用户
     * @param username
     * @return
     */
    @Select("select * from pt_user where username = #{username}")
    IUser findByUsername(String username);

    /**
     * 创建新用户
     * @param userDetail
     */

//    void insert(IUser userDetail);

    /**
     * 创建用户角色
     * @param userId
     * @param roleId
     * @return
     */
//    int insertRole(long userId,long roleId);

    /**
     * 根据角色id查找角色
     * @param roleId
     * @return
     */
    @Select("select * from pt_role where role_uuid = #{roleId}")
    IRole findRoleById(String roleId);

    /**
     * 根据用户id查找该用户角色
     * @param userId
     * @return
     */
    @Select("select * from pt_role where role_uuid = (select role_uuid from pt_role_user where user_uuid = #{id})")
    IRole findRoleByUserId(long userId);
}
